package com.ruoyi.yuyuan.Mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.yuyuan.Entity.Follow;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author: kestrel
 * @Version:1.0
 * @Date: 2024/5/29
 */
@Mapper
public interface FollowMapper extends BaseMapper<Follow> {
    /**
     * 查询userId是否有关注tarId
     * @param userId 用户id
     * @param tarId 目标用户id
     * @return Follow对象
     */
    @Select("select * from tb_follow where user_id = #{userId} and follow_user_id = #{tarId}")
    Follow isFollow(Long userId,Long tarId);

    @Select("select * from tb_follow where user_id = #{userId}")
    List<Follow> getTarFollowsByUserId(Long userId);

    @Select("select * from tb_follow where follow_user_id = #{userId}")
    List<Follow> getTarFollowersByUserId(Long userId);

    /**
     * 按照userId和followId删除数据
     * @param userId 用户id
     * @param followId 被关注的用户id
     * @return 成功与否
     */
    @Delete("delete from tb_follow where user_id = #{userId} and follow_user_id = #{followId}")
    public boolean deleteByUserIdAndFollowId(Long userId,Long followId);
}
